﻿using System;
using System.Windows;

namespace theeg.GeometryWpf
{
    public class ComputationalRectangle : ComputationalShape
    {
        /// <summary>
        /// left, right, top, bottom of rectangle
        /// </summary>
        public double L, T, R, B;
        /// <summary>
        /// get the width of the rectangle
        /// </summary>
        public double GetWidth()
        {
            return Math.Abs(R - L);
        }
        /// <summary>
        /// get the height of the rectangle
        /// </summary>
        public double GetHeight()
        {
            return Math.Abs(B - T);
        }

        public ComputationalRectangle()
        {
            BoundingBox = this;
        }

        public ComputationalRectangle(double left, double top, double right, double bottom)
        {
            L = left;
            R = right;
            T = top;
            B = bottom;
            BoundingBox = this;
        }

        public override bool Contains(Point pt)
        {
            return (L <= pt.X && R >= pt.X && T <= pt.Y && B >= pt.Y);
        }

        public override bool Contains(double x, double y)
        {
            return (L <= x && R >= x && T <= y && B >= y);
        }

        public override ShapeOverlapping Contains(ComputationalRectangle rect)
        {
            if (L > rect.R || R < rect.L || T > rect.B || B < rect.T) return ShapeOverlapping.Outside;
            int countx = 0, county = 0;
            if (L > rect.L) countx++;
            if (R < rect.R) countx++;
            if (T > rect.T) county++;
            if (B < rect.B) county++;
            if (countx == 0 && county == 0) return ShapeOverlapping.Contains;
            return ShapeOverlapping.Intersects;
        }
    }
}
